package org.ubc.cs410.disposal2020.client.view;

import org.ubc.cs410.disposal2020.client.dto.RobotDto;

import com.google.gwt.maps.client.geom.LatLng;
import com.google.gwt.maps.client.geom.Point;
import com.google.gwt.maps.client.overlay.Icon;
import com.google.gwt.maps.client.overlay.Marker;
import com.google.gwt.maps.client.overlay.MarkerOptions;
import com.google.gwt.user.client.DOM;

/*
 * Robot Marker Class 
 * Robot Marker is the icon for robot on the map
 */

public class RobotMarker extends Marker {
	private static final String ROBOT_ICON_PATH = "/robot.png";
	private static final String ROBOT_OPPONENT_ICON_PATH = "/robotBlue.png";
	private static final int ROBOT_ICON_WIDTH = 32;
	private static final int ROBOT_ICON_HEIGHT = 64;

	private RobotDto robot;

	public RobotMarker(RobotDto robot) {
		super(robot.getLocation(), initMarkerOptions(robot));
		this.robot = robot;
	}

	public RobotDto getRobot() {
		return robot;
	}

	private static MarkerOptions initMarkerOptions(RobotDto robot) {
		Icon icon = Icon.newInstance(ROBOT_ICON_PATH);
		icon.setIconAnchor(Point.newInstance(ROBOT_ICON_WIDTH, ROBOT_ICON_HEIGHT));
		MarkerOptions markerOptions = MarkerOptions.newInstance(icon);
		if (robot.getOwner().equals(DOM.getElementById("userEmail").getInnerHTML())) 
		{
			markerOptions.setDraggable(robot.isMovable());
		} else {
			icon = Icon.newInstance(ROBOT_OPPONENT_ICON_PATH);
			icon.setIconAnchor(Point.newInstance(ROBOT_ICON_WIDTH, ROBOT_ICON_HEIGHT));
			markerOptions = MarkerOptions.newInstance(icon);
			markerOptions.setDraggable(false);
		}
		return markerOptions;
	}

}
